package com.zhaosc.spark.sql.jdbc

import org.apache.spark.sql.SparkSession

object JDBCDataSource {
  def main(args: Array[String]): Unit = {
    
    val sparkSession = SparkSession.builder()
      .master("local")
      .appName("test").getOrCreate();

    val rdd = sparkSession.read.format("jdbc").option("url", "jdbc:mysql://localhost:3306/user-server")
      .option("driver", "com.mysql.jdbc.Driver")
      .option("dbtable", "t_top_message")
      .option("user", "root")
      .option("password", "123456")
      .load().rdd

    rdd.foreach(r => println(r.get(2)))
    
    sparkSession.sparkContext.stop();

  }
}